<?php

error_reporting(E_ALL ^ E_NOTICE | E_STRICT);

if (!in_array($_SERVER['HTTP_HOST'], array("localhost", "beta-radio.ru"))) {
#    header("Location: http://beta-radio.ru");
}

if (in_array($_SERVER['REMOTE_ADDR'], array("178.136.248.59", "178.219.244.155"))) {
    ini_set('display_errors', 'On');
    ini_set('html_errors', 'On');
}

date_default_timezone_set('Europe/Kiev');

set_include_path(
    '.'.PATH_SEPARATOR.
    'sys'.PATH_SEPARATOR.
    'sys/config'.PATH_SEPARATOR.
    'sys/config/tpl'.PATH_SEPARATOR.
    'sys/config/captcha'.PATH_SEPARATOR.
    'sys/admin'.PATH_SEPARATOR.
    'sys/user'.PATH_SEPARATOR.
    get_include_path());

session_start();

include('vars.php');
include('funct.php');

$PAGE = GetTpl("index");
$LINKS   = GetTpl('links');
$TARIFFS = "";
$NEWS    = GetTpl('news');
$NEW     = GetNews($GL);
$BANNERS = GetTpl('banners');

if ($_GET['action'] == "logout") {
    Logger($LogFile, "LOGOUT (".$_SESSION['LOGIN_NAME'].")");
    unset($_SESSION['LOGIN_OK']);
    unset($_SESSION['LOGIN_NAME']);
    unset($_SESSION['LOGIN_PASS']);
    unset($_SESSION['LOGIN_UID']);
    $_GET['action'] = "main";
}

if (!isset($_GET['action'])) { $_GET['action'] = "main"; }

if ($_GET['action'] != "login") { unset($_SESSION['LOGIN_TRY']); }

if ($_GET['action'] != "reg") { unset($_SESSION['REG_TRY']); }

if ($_GET['action'] == "main") { $TARIFFS = GetTpl('tariffs'); }

if ($_SESSION['LOGIN_OK']) {
    $HEADER = "Панель управления";
    if ($_SESSION['LOGIN_NAME'] == $GL["admin_user"]) {
        $NEWS = NULL;
        switch ($_GET['action']) {
            case "confirm": include('a_confirm.php');   break;
            case "extend":  include('a_extend.php');    break;
            case "change":  include('a_change.php');    break;
            case "del":     include('a_del.php');       break;
            case "stop":    include('a_stop.php');      break;
            case "start":   include('a_start.php');     break;
            case "stop2":   include('a_stop2.php');     break;
            case "start2":  include('a_start2.php');    break;
            case "noreg":  include('a_noreg.php');    break;
            case "logs":    include('a_logs.php');      break;

            case "addnew":  include('a_addnew.php');    break;
            case "ednew":   include('a_ednew.php');     break;
            case "delnew":  include('a_delnew.php');    break;

            case "addpage": include('a_addpage.php');   break;
            case "edpage":  include('a_edpage.php');    break;
            case "delpage": include('a_delpage.php');   break;

            case "panel":   include('a_main.php');      break;
            case "edit_playlist":   include('a_edit_playlist.php');      break;
        }
    }
    else {
        switch ($_GET['action']) {
            case "ftp":     include('u_ftp.php');       break;

            case "list":    include('u_list.php');      break;

            case "del":     include('u_del.php');       break;

            /*
            case "stop":    include('u_stop.php');      break;
            case "start":   include('u_start.php');     break; 
             */
            case "none":    include('u_none.php');      break;

            case "stop2":   include('u_stop2.php');     break;
            case "start2":  include('u_start2.php');    break;
            case "next":    include('u_next.php');      break;
            case "script":    include('u_script.php');   break;
            case "stat":    include('u_stat.php');        break;
            case "playlist":    include('u_playlist.php');        break;
            case "edit_playlist":    include('u_edit_playlist.php');        break;
            case "panel":   include('u_main.php');      break;
        }
    }
    $BODY .= $t_BODY;
}

switch ($_GET['action']) {
    case "news":
        $NEWS = "";
        include('news.php');
        break;
    case "login":
        $HEADER = "Вход";
        include('login.php');
        break;
    case "reg":
        $HEADER = "Регистрация";
        include('reg.php');
        break;
    case "regok":
        $HEADER = "Регистрация начата";
        $BODY = "<span>Инструкциями по активации отправлены на указанный email.</span>";
        break;
    case "actok":
        $HEADER = "Активация";
        $BODY = "<span>Регистрация завершена. Можете перейти в <a href=\"/?action=panel\">панель управления</a> радиостанцией.</span>";
        break;
    case "regdo":
        $HEADER = "Активация";
        include('confirm.php');
        break;
    case "nouser":
        $HEADER = "Ошибка";
        $BODY = "<span>Пользователя с таким ID не существует.</span>";
        break;
    case "error":
        $HEADER = "Ошибка";
        $BODY = "<span>Возникла непредвиденная ошибка.</span>";
        break;
    default:
        include('pages.php');
        break;
}

include('lpanel.php');

$change = array(

    "{LPANEL}"  => $LPANEL,
    "{LINKS}"   => $LINKS,
    "{TARIFFS}" => $TARIFFS,
    "{NEWS}"    => $NEWS,
    "{NEW}"     => $NEW,
    "{BANNERS}" => $BANNERS,

    "{SITE}" => $SITE,
    "{SCRIPTS}" => $SCRIPTS,
    "{HEADER}" => $HEADER,
    "{TITLE}" => $TITLE . " - " . $HEADER,
    "{CHARSET}" => $CHARSET,
    "{DESCRIPTION}" => $DESCRIPTION,
    "{AUTHOR}" => $AUTHOR,
    "{COPYRIGHT}" => $COPYRIGHT,
    "{BODY}" => $BODY);

foreach ($change as $k => $v) {
    $PAGE = str_replace($k, $v, $PAGE);
}

echo CompressHtml($PAGE);

?>